//
//  SleepHRVAverageView.swift
//  DaRings
//
//  Created by 易先生 on 2022/11/2.
//

import UIKit
import MYModule


open class HeartRateChartLineView: View {
    
    
    public var config: HeartRateChartLineConfig? {
        
        didSet {
            
            guard let config = config else {
                fillChartView.hrvLabel.text = "--"
                fillChartView.maxHRVView.dataLabel.text = "--"
                fillChartView.minHRVView.dataLabel.text = "--"
                startSleepTimeLabel.text = "--"
                endSleepTimeLabel.text =  "--"
                fillChartView.hearts = nil
                return
            }
            if let avg = config.avg {
                fillChartView.hrvLabel.text = "\(avg)"
            } else {
                fillChartView.hrvLabel.text = "--"
            }
            
            if let high = config.high {
                fillChartView.maxHRVView.dataLabel.text = "\(high)"
            } else {
                fillChartView.maxHRVView.dataLabel.text = "--"
            }
            if let low = config.low {
                fillChartView.minHRVView.dataLabel.text = "\(low)"
            } else {
                fillChartView.minHRVView.dataLabel.text = "--"
            }
            
            startSleepTimeLabel.text = config.startTime
            endSleepTimeLabel.text = config.endTime
            fillChartView.hearts = config.list
        }
        
    }
    

   public let fillChartView = HeartRateChartFillView()

    open override func makeUI() {
        super.makeUI()
        
        self.addSubview(fillChartView)
        self.addSubview(startSleepTimeLabel)
        self.addSubview(endSleepTimeLabel)
        
        fillChartView.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
        }
        
        startSleepTimeLabel.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(20)
            make.top.equalTo(fillChartView.snp.bottom)
            make.bottom.equalToSuperview()
        }
        
        endSleepTimeLabel.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-20)
            make.top.equalTo(fillChartView.snp.bottom)
        }
        
    }

   
    public lazy var startSleepTimeLabel: Label = {
        let startSleepTimeLabel = Label()
        startSleepTimeLabel.text = "sleep_fail_asleep".language(with: ["--"])
        startSleepTimeLabel.textColor = UIColor.assist_222222
        startSleepTimeLabel.font = Fonts.systemFont(ofSize: 10)
        return startSleepTimeLabel
    }()
    
    public lazy var endSleepTimeLabel: Label = {
        let endSleepTimeLabel = Label()
        endSleepTimeLabel.text = "sleep_wake_up".language(with: ["--"])
        endSleepTimeLabel.textColor = UIColor.assist_222222
        endSleepTimeLabel.font = Fonts.systemFont(ofSize: 10)
        return endSleepTimeLabel
    }()
    
}
